import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Request, UseGuards } from "@nestjs/common";
import { JwtAuthGuard } from "src/modules/auth/guard/jwt-auth.guard";
import { OrderService } from "src/service/order.service";
import { OrderEntity } from "../Entity/order.entity";


@Controller('order')
export class OrderController {
    constructor(
        private readonly orderService: OrderService,
    ) { }

    @Get()
    async findAll(): Promise<OrderEntity[]> {
        return this.orderService.findAll();
    }

    @UseGuards(JwtAuthGuard)
    @Post()
    async createOrder(@Request() req, @Body() item: OrderEntity) {

        return this.orderService.create(req.user.userId, item);
    }

    @Get('/orderNo/:orderNo')
    async findOne(@Param('orderNo') orderNo: string) {
        return this.orderService.findOne(orderNo);
    }


    @Delete('/orderNo/:orderNo')
    async deleteOrder(@Param('orderNo') orderNo: string) {
        console.log(orderNo);

        return this.orderService.deleteOrder(orderNo);
    }

    @Put()
    async updateOrder(@Body() item: OrderEntity) {
        // console.log(item);
        return this.orderService.updateOrder(item);
    }
s
    @Get('/startTime/:startTime')
    async getOne(@Param('startTime') startTime: Date) {
       
        return this.orderService.getOne(startTime);
    }
}


